<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>试题管理</title>
    <link href="../resources/bootstrap/css/bootstrap.css" rel="stylesheet">
    <link href="../resources/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <link href="../resources/css/style.css" rel="stylesheet">
    <link href="../resources/css/exam.css" rel="stylesheet">

    <script type="text/javascript" src="../resources/js/jquery/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="../resources/vue/vue.js"></script>
    <script type="text/javascript" src="../resources/vue/date.js"></script>
    <script type="text/javascript" src="../resources/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../resources/js/all.js"></script>
    <script type="text/javascript" src="../resources/js/tag-list.js"></script>
    <script type="text/javascript" src="../resources/js/add-tag.js"></script>
    <script type="text/javascript" src="../resources/js/add-tag.js"></script>
    <script type="text/javascript" src="../resources/js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script type="text/javascript" src="../resources/laypage/laypage.js" charset="utf-8"></script>
    <script type="text/javascript" src="../resources/layui/layui.all.js" charset="utf-8"></script>
    <script type="text/javascript" src="../resources/bootstrap/js/bootstrapValidator.min.js"></script>
    <link href="../resources/bootstrap/css/bootstrapValidator.min.css" rel="stylesheet">
</head>
<body>


<div>


    <div class="container" style="min-height:500px;">
        <div >
                <div class="page-header">
                    <h1><i class="glyphicon glyphicon-random"></i> 添加标签 </h1>
                </div>
                <div style="padding-left: 100px;">

                    <form id="tag-add-form" style="margin-top:40px;">

                        <div class="form-group">
                            <span class="form-label"><span class="warning-label"></span>标签名：</span>
                            <input type="text" class="form-control" id="name" name="tagName" placeholder="请输入标签名">
                            <br>
                        </div>
                        <div class="form-group">
                            <span class="form-label"><span class="warning-label"></span>标签描述：</span>
                            <input type="text" class="form-control" id="memo" name="memo" placeholder="请输入标签描述"><span
                                class="form-message"></span>
                            <br>
                        </div>


                        <div class="form-group">
                            <!--<input id="btn-save" value="确认添加" type="submit" class="df-submit btn btn-info">-->
                            <button type="button" id="btn-save" class="df-submit btn btn-info">提交</button>
                            <button type="button" id="btn-cancle" class="df-submit btn btn-info">取消</button>
                        </div>
                    </form>
            </div>
        </div>
    </div>
</div>

</body>
</html>

<script>

    var addTag = function () {
        $.ajax({
            type: 'post',
            dataType: 'json',
            url: '/addTag',
            data: $("#tag-add-form").serialize(),
            success: function (data) {
                if (data > 0) {
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.getTagPageList();
                    parent.layer.close(index);
                    $("#btn-cancle").click();
                }
            }, error: function () {
          //      alert("添加失败");
            }

        });
    };


    $("#btn-save").click(function () {
        $("#tag-add-form").bootstrapValidator('validate');//提交验证
        if ($("#tag-add-form").data('bootstrapValidator').isValid()) {//获取验证结果，如果成功，执行下面代码
            addTag();
        }
    });


    $('#tag-add-form').bootstrapValidator({
        live: 'enabled',//验证时机，enabled是内容有变化就验证（默认），disabled和submitted是提交再验证
        excluded: [':disabled', ':hidden', ':not(:visible)'],//排除无需验证的控件，比如被禁用的或者被隐藏的
        submitButtons: '#btn-save',//指定提交按钮，如果验证失败则变成disabled
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            tagName: {
                validators: {
                    notEmpty: {//检测非空,radio也可用
                        message: '必须输入标签名'
                    },
                    stringLength: {//检测长度
                        min:2,
                        max: 20,
                        message: '长度必须在2-20之间'
                    },

                }
            },
            memo: {
                validators: {
                    notEmpty: {//检测非空,radio也可用
                        message: '必须输入描述'
                    },
                    stringLength: {//检测长度

                        max: 50,
                        message: '长度必须在小于50'
                    }

                }
            }
        }
    });


    $("#btn-cancle").click(function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.getTagPageList();
        parent.layer.close(index);

    });

</script>